//
//  AppDelegate.m
//  WHEasyBizLink
//
//  Created by shengmeng chen on 2024/11/22.
//

#import "AppDelegate.h"
#import "WHTabBarController.h"
#import "HttpTool.h"
#import "AFNetworking.h"
#import "WHLoginModel.h"
#import "WHLoginViewController.h"



@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    kApp.isHadNetwork = YES;
    //检测网络状态的变化
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    
    [self checkNetWorckStatus];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];

    //关闭夜间模式
    if(@available(iOS 13.0,*)){
        self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    }
   
    WHLoginModel*model = [WHLoginModel getLoginModel];
    if (model.phone.length>0) {
        kApp.userPhone =model.phone;
        kApp.userQcode =model.qcode;
        kApp.userName  =model.username;
        
        WHTabBarController *controller = [[WHTabBarController alloc] init];
        self.window.rootViewController = controller;
        [self.window makeKeyAndVisible];
        
    }else
    {
        WHLoginViewController *vc = [[WHLoginViewController alloc] init];
        self.window.rootViewController = vc;
        [self.window makeKeyAndVisible];
    }
    
    return YES;
}

-(void)checkNetWorckStatus
{
    [HttpTool checkRunTimeNetworkStatusSuccess:^(id responseObject)
     {
        kApp.isHadNetwork = YES;
        
    } failure:^(NSString *error) {
        
        kApp.isHadNetwork = NO;
    }];
}
@end
